/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lenovo
 * Date: 2025-08-22
 * Time: 19:12
 */
//https://leetcode.cn/problems/product-of-array-except-self/submissions/655585380/
public class Test {
    public static int[] productExceptSelf(int[] nums) {
        int size=nums.length;
        int[] arr=new int[size];
        int[] brr=new int[size];
        int sum=1;
        for(int i=0;i<size;i++){
            sum*=nums[i];
            arr[i]=sum;
        }
        sum=1;
        for(int i=size-1;i>=0;i--){
            sum*=nums[i];
            brr[i]=sum;
        }
        for(int i=1;i<size-1;i++){
            nums[i]=arr[i-1]*brr[i+1];
        }
        nums[0]=brr[1];
        nums[size-1]=arr[size-2];
        return nums;
    }
    public static void main(String[] args) {
        int[] arr={1,2,3,4};
        int[] brr=productExceptSelf(arr);
        for(int i=0;i<brr.length;i++){
            System.out.print(brr[i]+" ");
        }

    }

}
